#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include "gputimer.h"
#include <stdio.h>
#include <stdlib.h>


#define DATA_TYPE double
#define INDICE_TYPE int 

#define NEARESTENTITY_VN0 0
#define NEARESTENTITY_VN1 1
#define NEARESTENTITY_VN2 2
#define NEARESTENTITY_EN0 3
#define NEARESTENTITY_EN1 4
#define NEARESTENTITY_EN2 5
#define NEARESTENTITY_FN 6


#define SINGLE_MESH_VERTICE_COUNT 3
#define VERTICE_WIDTH 3
#define NE_WIDTH 4

#define BLOCK_WIDTH 1024

#define PRINT_INFO

__global__
void
distance(
	int *thread_num,
	DATA_TYPE *p, DATA_TYPE *point_data, INDICE_TYPE *mesh_indices,
	DATA_TYPE *result_d2, DATA_TYPE *result_nearest_point, int *result_ne);
	
__global__
void
min_reduce1(
	int *thread_num,
	DATA_TYPE *arr, int *ids
);


__global__
void
min_reduce2(
	int *block_num, int *ids,
	DATA_TYPE *arr_d2, DATA_TYPE *arr_nearest_point, int *arr_ne);
	
	
extern "C" int run(
	DATA_TYPE p_x, DATA_TYPE p_y, DATA_TYPE p_z,
	DATA_TYPE *point_data, int point_count, INDICE_TYPE *mesh_indices, int mesh_count,
	int *id, DATA_TYPE *d2, DATA_TYPE *nearest_point, int *ne);